package com.itheima.d3_stringbuilder;

import java.util.StringJoiner;

/*
   为啥操作字符串建议使用StringBuilder，而不用原来学过的String??
        1) 对于字符串相关的操作，如频繁的拼接、修改等，建议用StringBuilder，效率更高!
        2) 注意：如果操作字符串较少，或者不需要操作，以及定义字符串变量，还是建议用String。
 */
public class StringBuilderDemo2 {

    public static void main(String[] args) {

//        long start = System.currentTimeMillis() ;
//        String s = "";
//        for (int i = 0; i < 100000; i++) s+="哈";
//        long end = System.currentTimeMillis();
//        System.out.print(end-start);


        long start = System.currentTimeMillis() ;
        int[] arr = {1,3,5,7,9,0};
//        StringBuilder sb = new StringBuilder();
        StringJoiner sb = new StringJoiner(",","[","]");
//        for (int i = 0; i < 100000; i++) sb.add("哈");
//        long end = System.currentTimeMillis();
//        System.out.print(end-start);
//        System.out.println(sb);
        for (int i = 0; i < arr.length  ; i++) {
            sb.add(arr[i] + "");
        }
        System.out.println(sb);
//        for (int i = 0; i < arr.length; i++) {
//            System.out.print(arr[i] + " ");
//        }

    }


}
